<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends StudyBaseAction {
	public function index(){
		//	$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
		$this->display('Index:index');
	}
	public function main(){
		$this->display('Index:main');
	}
	public function log(){
		$this->display('Index:login');
	}
	public function apply(){
		$this->display();
	}
	//用户登录
	public function login()
	{
		$username = $_POST['username'];
		$password = $_POST['password'];

		if(!empty($username) && !empty($password))
		{
			$username = trim($username);
			$user = M('User');
			$condition['username'] = $username;
			$condition['password'] = $password;
			$data = $user->where($condition)->select();
			echo var_dump($data);
			if (empty($data))
			{
				$this->display('Index:login');
			}
			else
			{
				$_SESSION["user"] = $data[0];
				//					$this->redirect('/index.php/Index/index2');
				$this->redirect('/Index/index2');
			}
		}
		else
		{
			$this->display('Index:login');
		}
	}
	/**
	 * 查看帖子
	 */
	public function share_community()
	{
		$note = M('Note');
		$where['id'] = $_GET['id'];//$_GET['id']
		$count=$note->where($where)->getField('number');
		//查看列表查看次数加一
		$counts = (int)$count + 1;
		$data['number'] = $counts;
		$note->where($where)->data($data)->save();
		//课程
		$note = M('Note');
		$where_id['s_note.id'] = $_GET['id'];
		$noteList = $note ->field('s_note.*,u.username,note.note_count,u.image as image_user,(TO_DAYS(now()) - TO_DAYS(s_note.create_time)) as days') ->join("left join s_user u on u.id=s_note.user_id
        	left join (select count(id) as note_count,note_id from s_note_one group by note_id) as note on note.note_id= s_note.id")->where($where_id)->find();
		//评论
		$note_one = M('Note_one');
		$note_id['note_id'] = $_GET['id'];
		$noteOneList = $note_one->field('s_note_one.*,u.username,u.image as image_user,(TO_DAYS(now()) - TO_DAYS(s_note_one.create_time)) as days')->join("left JOIN s_user u on s_note_one.user_id = u.id ")->where($note_id)->select();
		//二级评论
		$note_two = M('Note_two');
		$note_id_two["o.note_id"] = $_GET['id'];
		$noteTwoList = $note_two->field('s_note_two.*,u.username as name,uu.username as twoname,(TO_DAYS(now()) - TO_DAYS(s_note_two.create_time)) as days')->where($note_id_two)->join("left JOIN s_user u on s_note_two.user_id = u.id left JOIN s_note_one o on s_note_two.note_one_id = o.id left JOIN s_user uu on o.user_id = uu.id  ")->select();
		//图片
		$note_image = M('Note_image');
		$note_id_image["note_id"] = $_GET['id'];
		$noteImage = $note_image->where($note_id_image)->select();
		 
		//1图片
		$note_one_image = M('Note_one_image');
		$noteOneImage = $note_one_image->where($note_id_image)->select();
		 
		//2图片
		$note_two_image = M('Note_two_image');
		$noteTwoImage = $note_two_image->where($note_id_image)->select();
		 
		$this->assign("list",$noteList);
		$this->assign("noteOne",$noteOneList);
		$this->assign("noteTwo",$noteTwoList);
		$this->assign("noteImage",$noteImage);
		$this->assign("noteOneImage",$noteOneImage);
		$this->assign("noteTwoImage",$noteTwoImage);
		$this->display();
	}

}